﻿using Projectframes.DeviceSetFroms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
using YJYpublicClass;
using YJYpublicClass.DataStruct;

namespace Projectframes.DeviceClasses
{
    public class AppDevice 
    {
        public AppDeviceConfig Config = new AppDeviceConfig();
        public string Savepath = "系统.xml";

        public AppDevice()
        {
          
        }
        public AppDevice(string path)
        {
            Savepath = path;     
        }
        public ResultFunc Saveconfig()
        {
            try
            {
                if (XmlHelper.SaveXML(Savepath, Config) == "")
                {
                    return new ResultFunc(Funstate.OK, "");
                }
                else
                {
                    return new ResultFunc(Funstate.异常, "保存失败");
                }
            }
            catch (Exception ex)
            {

                return new ResultFunc(Funstate.异常, ex.ToString());
            }

        }

        public void LoadConfig()
        {
            if (!File.Exists(Savepath))
            {
                Config = new AppDeviceConfig();
            }
            else
            {
                Config = XmlHelper.LoadXML<AppDeviceConfig>(Savepath);
            }
        }
        //初始化也一并完成
        public void setConfig()
        {
            Frm_system temp = new Frm_system(this);
            temp.Show();
        }

    }
    public class AppDeviceConfig {

        [Category("系统"), Description("string"), DisplayName("设备名"), ReadOnly(false)]
        public string Devicename { get; set; } = "系统";
        [XmlIgnore]
        [Category("系统路径"), Description("string"), DisplayName("保存路径"), ReadOnly(false)]
        public string savepath { get; set; } = "系统";

        [XmlIgnore]
        [Category("系统路径"), Description("string"), DisplayName("日志路径"), ReadOnly(false)]
        public string LogPath { get; set; } = "D:\\CCD日志";

        [Category("系统路径"), Description("string"), DisplayName("图片路径"), ReadOnly(false)]
        public string SaveImagePath { get; set; } = "D:\\CCD图片";


        [Category("系统路径"), Description("string"), DisplayName("测量结果路径"), ReadOnly(false)]
        public string CsvPath { get; set; } = "";

        [Category("系统"), Description("string"), DisplayName("图像保存天数"), ReadOnly(false)]
        public int DeleteImageTime { get; set; } = 4;
        [Category("系统"), Description("string"), DisplayName("日志保存天数"), ReadOnly(false)]
        public int DeleteLogTime { get; set; } = 4;
        [Category("系统"), Description("string"), DisplayName("工程路径"), ReadOnly(false)]
        public string _VPP工程文件夹 { get; set; } = "";

        [Category("参数"), Description("float"), DisplayName("语言设置"), ReadOnly(false)]
        public int _语言 { get; set; } = 0;
        [Category("软件参数"), Description("string"), DisplayName("最近款式名"), ReadOnly(true)]
        public string _前次款式 { get; set; }

        [Category("软件参数"), Description("string"), DisplayName("开机开启检测"), ReadOnly(true)]
        public Boolean _开机开启检测 { get; set; } = false;
        [Category("软件参数"), Description("string"), DisplayName("高度检测"), ReadOnly(false)]
        public Boolean _高度检测 { get; set; } = true;

        [XmlIgnore]
        [Category("系统路径"), Description("string"), DisplayName("日志路径"), ReadOnly(false)]
        public List<_款式索引> _款式集合 { get; set; } = new List<_款式索引>();
        //控制参数  
        public string getName()
        {
            return Devicename;
        }
        public AppDeviceConfig()
        {
            LogPath = @"D:\appdata\log";
            CsvPath = @"D:\appdata\CSV";

        }
   

    }


}
